package com.sikao.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.adapter.PersonalCenterAdapter;
import com.sikao.app.ui.base.BaseActivity;

/**
 * 卖家中心
 */
public class SellerCenterActivity extends BaseActivity implements View.OnClickListener {

	private TextView titleTv;
	private ImageView backIv;
	private ListView listView;
	private PersonalCenterAdapter adapter;
	private String[] titles;
	private Intent intent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_seller_center);
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void initData() {
		titles = getResources().getStringArray(R.array.seller_title);
	}

	@Override
	protected void initView() {
		titleTv = (TextView) findViewById(R.id.title_middle_tv);
		backIv = (ImageView) findViewById(R.id.title_left_img);
		listView = (ListView) findViewById(R.id.listView);
	}

	@Override
	protected void initListener() {
		backIv.setOnClickListener(this);
		listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				if (intent == null) {
					intent = new Intent();
				}
				switch (position) {
					case 0:
						//卖家订单
						intent.setClass(SellerCenterActivity.this, SellerOrderActivity.class);
						break;
					case 1:
						//我的投标记录
						intent.setClass(SellerCenterActivity.this, SellerBidRecordActivity.class);
						break;
					case 2:
						//发布商品
						intent.setClass(SellerCenterActivity.this, ReleaseGoodsActivity.class);
						/*
						（1）、初次进入 1
                        （2）、第二步返回状态 2
                        （3）、查询重新编辑状态3

                        releaseGoodsState  1，2，3

                        状态为3的时候需要goodsId参数
						 */
						intent.putExtra("releaseGoodsState", 1);
						break;
					case 3:
						//我发布的商品
						intent.setClass(SellerCenterActivity.this, MyReleaseGoodsActivity.class);

						break;
					default:
						return;
				}
				startActivity(intent);
			}
		});
	}

	@Override
	protected void init() {
		titleTv.setText("卖家中心");
		backIv.setVisibility(View.VISIBLE);
		adapter = new PersonalCenterAdapter(this, titles);
		listView.setAdapter(adapter);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.title_left_img:
				finish();
				break;
			default:
				break;
		}
	}
}
